country=input('Enter the name of your home country: ')ifcountry=='canada':# string comparisons are case sensitive# if you typed in CANADA or Canada it will not matchprint('So you must like hockey!')else:print('You are not from Canada')
1
2
3
4
5
6
7
8
9
10
11
12
#Calculate the tax# Anything purchased for more than $1.00 is charged a 7% taxprice=input('how much did you pay? ')# Convert the string to a numberprice=float(price)# Check if the price is greater than 1.00ifprice>=1.00:# Everything over $1.00 is charged 7% taxtax=.07print('Tax rate is: '+str(tax))
country='CANADA'# by converting the string entered to lowercase and comparing it to a string# that is all lowercase letters I make the comparison case-insensitive# If someone types in CANADA or Canada it will still be a matchifcountry.lower()=='canada':print('Hello eh')else:print('Hello')
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
price=input('how much did you pay? ')price=float(price)ifprice>=1.00:# Anything that costs $1.00 or more is charged 7% tax# All statements indented are only executed if price is > = 1tax=.07print('Tax rate is: '+str(tax))else:# Anything else we do not charge any tax# All statements indented are only executed if price is NOT >= 1 tax=0print('Tax rate is: '+str(tax))
1
2
3
4
5
6
7
8
price=5.0ifprice>=1.00:tax=.07else:tax=0# the print statement below is not indented so is executed after the if # statement is evaluatedprint(tax)
Check the following script and try to find the mistake:
1
2
3
4
5
6
7
8
9
10
11
12
# Fix the mistakes in this code and test based on the description below# If I enter 2.00 I should see the message "Tax rate is: 0.07" # If I enter 1.00 I should see the message "Tax rate is: 0.07" # If I enter 0.50 I should see the message "Tax rate is: 0" price=input('how much did you pay? ')ifprice>1.00:tax=.07print('Tax rate is: '+str(tax))elsetax=0print('Tax rate is: '+str(tax))
solutions:
1
2
3
4
5
6
7
8
9
10
11
12
13
# Fix the mistakes in this code and test using the following# If I enter 2.00 I should see the message "Tax rate is: 0.07" # If I enter 1.00 I should see the message "Tax rate is: 0.07" # If I enter 0.50 I should see the message "Tax rate is: 0" price=input('how much did you pay? ')price=float(price)ifprice>=1.00:tax=.07print('Tax rate is: '+str(tax))else:tax=0print('Tax rate is: '+str(tax))